package com.assistant.util;

import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * CookieUtil
 *
 * @author yingjianhua
 */
@Component
public class CookieUtil {

    private static final String COOKIE_KEY = "set-cookie";

    public Map<String, String> resolve(HttpHeaders headers) {
        Map<String, String> map = new HashMap<>(16);
        final List<String> cookieStrList = headers.get(COOKIE_KEY);
        if (!CollectionUtils.isEmpty(cookieStrList)) {
            for (String it : cookieStrList) {
                String[] cookie = it.split(";")[0].split("=");
                map.put(cookie[0], cookie[1]);
            }
        }
        return map;
    }
}
